'use strict';

/**
 * @ngdoc function
 * @name webApp.controller:SigninCtrl
 * @description
 * # SigninCtrl
 * Controller of the webApp
 */

angular.module('webApp')
  .controller('signIn', function ($scope,cookie,promiseSignIn,popBox,$location,$localStorage) {
    //获得焦点时候的滚动事件
    $scope.$on('$stateChangeSuccess',function(){
      $scope.user = {
        username: '',
        password: ''
      };
    });
    $scope.submit = function(){
      if($scope.user.username != '' && $scope.user.password != ''){
        promiseSignIn.signIn($scope.user).then(function(data){
          popBox.showConfirm('提示','登录成功！');
          $localStorage.access_token = data.access_token;
          cookie.setCookie('access_token',data.access_token,'s' + data.expires_in);
          $location.path('/root/home');
        });
      }
      else{
        popBox.showConfirm('警告','登录填写信息不完整！');
      }
    };
});
